package com.redxiii.spike.pmi.command;

import java.util.Collection;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.redxiii.spike.api.command.CommandFactory;
import com.redxiii.spike.api.command.InitializationRequired;
import com.redxiii.spike.api.message.ImMessage;
import com.redxiii.spike.api.pmi.entity.Member;
import com.redxiii.spike.pmi.HandlerSession;
import com.redxiii.spike.util.command.InternetCommand;
import com.redxiii.spike.util.message.BasicMsgInterpreter;

/**
 * @author Daniel Filgueiras
 * @since 27/03/2012
 */
@InitializationRequired
@CommandFactory(BasicMsgInterpreter.class)
public class ShowMembers extends InternetCommand {

	private static final Logger logger = LoggerFactory.getLogger(ShowMembers.class);
	
	@Override
	public boolean proccess(ImMessage message) {
		
		StringBuilder buffer = new StringBuilder();
		
		Collection<Member> members = HandlerSession.getDatabase().getMembers();
		logger.debug("Got {} members", members.size());
		
		for (Member member : members) {
			buffer.append(member.getLogin()).append(": ").append(member.getMail()).append("\r\n");
		}
		
		service.reply(message, buffer);
		
		return true;
	}
	

}
